package com.ruoyi.framework.web.service;

import com.ruoyi.common.core.domain.DTO.InsertUserBankAccountBO;
import com.ruoyi.common.core.domain.DTO.UpdateUserBankAccountBO;
import com.ruoyi.common.core.domain.entity.UserBankAccount;
import com.ruoyi.system.mapper.UserBankAccountMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Component
@Transactional
public class UserBankAccountService {
    @Autowired
    private UserBankAccountMapper userBankAccountMapper;

    public void insertUserBankAccount(InsertUserBankAccountBO insertUserBankAccountBO) {
        UserBankAccount userBankAccount = new UserBankAccount();
        BeanUtils.copyProperties(insertUserBankAccountBO, userBankAccount);
        userBankAccount.setStatus(1);
        userBankAccount.setCreateTime(new Date());
        userBankAccount.setUpdateTime(new Date());
        userBankAccountMapper.insertUserBankAccount(userBankAccount);
    }

    public void updateUserBankAccount(UpdateUserBankAccountBO updateUserBankAccountBO) {
        UserBankAccount userBankAccount = new UserBankAccount();
        BeanUtils.copyProperties(updateUserBankAccountBO, userBankAccount);
        userBankAccount.setUpdateTime(new Date());
        userBankAccountMapper.updateUserBankAccount(userBankAccount);
    }

    public List<UserBankAccount> selectUserBankAccountByUserId(Long userId) {
        return userBankAccountMapper.selectUserBankAccountByUserId(userId);
    }

    public UserBankAccount selectUserBankAccountById(Long bankAccountId) {
        return userBankAccountMapper.selectUserBankAccountById(bankAccountId);
    }
}
